package com.jerry.netty.buffer;

import java.nio.IntBuffer;

public class BasicBuffer {

    public static void main(String[] args) {

        //创建一个大小为5的Buffer
        IntBuffer intBuffer = IntBuffer.allocate(5);

        //向buffer中存放数据
        for (int i=1; i<= intBuffer.capacity(); i++) {
            intBuffer.put(i * 2);
        }

        //将Buffer进行读写转换
        intBuffer.flip();     // 此方法特别重要

        //从buffer中读取数据
        while (intBuffer.hasRemaining()) {
            System.out.println(intBuffer.get());
        }

    }

}
